package team.seekers.hula.system.resource.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import team.seekers.hula.system.resource.entity.dto.AliDemandDTO;
import team.seekers.hula.system.resource.utils.AliVodUtil;

/**
 * date: 2022/4/25 21:45
 *
 * @author GH
 * QQ 1124813753
 */
@Slf4j
@Service
public class DemandService{

    /**
     * 获取音/视频上传地址和凭证
     */
    public AliDemandDTO uploadVideo(String title, String fileName) {
        try {
            return AliVodUtil.uploadVideo(title, fileName);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 刷新音/视频上传凭证
     */
    public AliDemandDTO refreshUploadVideo(String videoId) {
        try {
            return AliVodUtil.refreshUploadVideo(videoId);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 获取图片上传地址和凭证
     */
    public AliDemandDTO uploadImage(String imgName, String imgExt) {
        try {
            return AliVodUtil.uploadImage(imgName, imgExt);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 获取播放凭证函数
     */
    public AliDemandDTO getVideoPlayAuth(String videoId) {
        try {
            return AliVodUtil.getVideoPlayAuth(videoId);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 获取播放凭证函数
     */
    public String getVideoPlayUrl(String videoId) {
        try {
            return AliVodUtil.getPlayInfo(videoId).getPlayInfoList().get(0).getPlayURL();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 获取辅助媒资(水印、字幕等)上传地址和凭证
     * @param bType 业务类型watermark：水印;subtitle：字幕;material：素材。
     */
    public AliDemandDTO uploadAttachedMedia(String bType, String mediaName, String mediaExt) {
        try {
            return AliVodUtil.uploadAttachedMedia(bType, mediaName, mediaExt);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}
